	function loadMotions(){
		$.ajax({ 
			url: "/ki/listmotions", 
			dataType : 'json',
			success: function(data){
				$('ul#ki_list_motions li').remove();
				jQuery.each(data,function(k,v){
					var innerText = v.replace(/_/g,' ');
					$('<li id="motion_'+k+'"  ><a href="#">' + innerText + '<span class="ui-li-count">'+k+'</span></a></li>').appendTo('ul#ki_list_motions').click(function(){
						$("li#motion_"+k+" a").html("running motion : " +k + " " + v);
						$.ajax({ 
							url: "/ki/runmotion/"+k, 
							dataType : 'json',
							success: function(data){
								$("li#motion_"+k+" a").html(innerText);
							}
						});	
					}); 
				});
				$('ul#ki_list_motions').listview('refresh');
			}
		});
	}
	function loop_status() { 
		$.ajax({ 
			url: "/ki/status", 
			dataType : 'json',
			success: function(data){
				if (!data) return;
				$("#ki_battery_level").empty().html(data.connected?data.battery_level:"-");
				$("#ki_connected").empty().html(data.connected?"on":"off");
				var timestamp = new Date().getTime();
				setTimeout(loop_status, 5*1000)
				
			}
		}); 
	}
	function loop_img() { 
		var timestamp = new Date().getTime();
		$('#pic_capture').attr('src','/cv/capture?tmp='+timestamp);
		$('#pic_motion').attr('src','/cv/motion?tmp='+timestamp);
		setTimeout(loop_img, 1*1000)
	}
	
	function initMoves(){
		var moves={
		'bt_move_turnleft'	:20,
		'bt_move_forward'	:22,//16,
		'bt_move_turnright'	:21,
		'bt_move_left'		:18,
		'bt_move_stop'		:-1,
		'bt_move_right'		:19,
		'bt_move_standback'	:15,
		'bt_move_backward'	:23,//17,
		'bt_move_standfront':14,
		'bt_move_head'		:6
		};
		jQuery.each(moves,function(k,v){
			$('#'+k).click(function(){
				console.log(k,v);
				var url = (v==-1)?"/ki/stopmotion":"/ki/runmotion/"+v;
				$.ajax({ 
					url: url, 
					dataType : 'json',
					success: function(data){
						
					}
				});
				return false;
			})
		});
	}